﻿Imports System.Deployment.Application
Public Class frmAbout

    Private Declare Function ShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" _
        (ByVal hwnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) As Long

    Private Const SW_SHOWNORMAL = 1
    Private Const SW_HIDE = 0

    Private Function GetFileVersionInfo(ByVal filename As String) As Version
        Return Version.Parse(FileVersionInfo.GetVersionInfo(filename).FileVersion)
    End Function

    Private Sub frmAbout_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.Icon = frmMain.Icon
        Dim LibRef As New OpenVPNWinSvc.Library.OpenVPNTunMgr
        Dim CntRef As New OpenVPNWinSvc.Library.OpenVPNCntrl


        lblCopyright.Text = "© 2012 - " & Now.Year & " by Chris Burri - MIT License"
        lsvComponents.Items.Clear()
        lsvComponents.Items.Add("OpenVPNWinSvc.Library.dll").SubItems.Add("Unknown")
        lsvComponents.Items.Add("OpenVPNWinSvc.Service.exe").SubItems.Add("Unknown")
        lsvComponents.Items.Add("OpenVPNWinSvc.GUI.exe").SubItems.Add("Unknown")
        lsvComponents.Items.Add("openvpn.exe").SubItems.Add("Unknown")

        Try
            lsvComponents.Items(0).SubItems(1).Text = LibRef.ComponentVersion
        Catch ex As Exception
            lsvComponents.Items(0).SubItems(1).Text = "N/A"
        End Try
        Try
            lsvComponents.Items(1).SubItems(1).Text = GetFileVersionInfo("OpenVPNWinSvc.Service.exe").ToString
        Catch ex As Exception
            lsvComponents.Items(1).SubItems(1).Text = "N/A"
        End Try
        Try
            lsvComponents.Items(2).SubItems(1).Text = GetVersionInfo()
        Catch ex As Exception
            lsvComponents.Items(2).SubItems(1).Text = "N/A"
        End Try
        Try
            lsvComponents.Items(3).SubItems(1).Text = CntRef.GetOVPNVersion
        Catch ex As Exception
            lsvComponents.Items(3).SubItems(1).Text = "N/A"
        End Try
        CntRef = Nothing
        LibRef = Nothing
        GC.Collect()

    End Sub

    Private Sub LinkLabel2_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
        Me.Close()
    End Sub

    Private Sub lnkWordpress_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkWordpress.LinkClicked
        ShellExecute(CLng(Me.Handle), "open", "http://niston.wordpress.com", vbNullString, "c:\", SW_SHOWNORMAL)
    End Sub

    Private Sub lnkCodeplex_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkCodeplex.LinkClicked
        ShellExecute(CLng(Me.Handle), "open", "http://openvpnwinsvc.codeplex.com", vbNullString, "c:\", SW_SHOWNORMAL)
    End Sub

    Private Function GetVersionInfo() As String
        If (ApplicationDeployment.IsNetworkDeployed) Then
            Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment
            Return AD.CurrentVersion.ToString
        Else
            Return My.Application.Info.Version.ToString
        End If
    End Function
End Class